const InterviewSpeed = require("../models/interviewSpeedModel");

//获取所有访谈进度(审核员)
exports.getAllInterviewSpeed = async (req, res) => {
  try {
    const interviewSpeed = await InterviewSpeed.find();
    res.status(200).json({
      status: "success",
      data: interviewSpeed,
    });
  } catch (err) {
    console.log("获取所有访谈进度失败", err);
    res.status(404).json({
      Error: err,
    });
  }
};

//获取指定分组的所有访谈进度（管理员）
exports.getInterviewSpeedByGroup = async (req, res) => {
  try {
    const interviewSpeedData = await InterviewSpeed.find({
      group: req.user.group,
    });
    res.status(200).json({
      status: "success",
      data: interviewSpeedData,
    });
  } catch (error) {
    console.log("获取指定分组的所有访谈失败", err),
      res.status(404).json({
        Error: error,
      });
  }
};

//添加访谈进度
exports.createInterviewSpeed = async (req, res) => {
  try {
    const addInterview = await InterviewSpeed.create(req.body);
    res.status(201).json({
      status: "success",
      data: addInterview,
    });
  } catch (err) {
    console.log("添加访谈进度失败", err);
    res.status(404).json({
      Error: err,
    });
  }
};

//删除指定分组的所有访谈进度（管理员）
exports.deleteAllInterviewSpeedByGroup = async (req, res) => {
  try {
    await InterviewSpeed.deleteMany({ group: req.user.group });
    res.status(200).json({
      status: "success",
      data: "批量删除成功",
    });
  } catch (err) {
    console.log("删除指定分组的所有访谈进度失败", err);
    res.status(404).json({
      Error: err,
    });
  }
};
